# !/usr/bin python3                                
# encoding: utf-8 -*-
# @file: strategy_flow_test.py                       
# @author   : wjd
# @Time: 2024/2/1 15:13

import allure
import pytest

from api.service_admin.checkout_params_apis import AuditInvestListApi, AuditInvestStatus, StrategyAdd
from api.service_sp.money_management_sp import Prime_InvestFixed_Add_FixedInfo, AuditSubmit, \
    PrimeInvestFixedGetFixedInfoList
from common.random_util import rdm_phone_number


@allure.feature('服务商平台+运营平台')
class TestBuyNowApi:
    @allure.story('创建理财策略流程')
    @pytest.mark.parametrize('name, currency, LimitMax, LimitMin, returnTime_days, investEndTime_days',
                             [("脚本测试", "ETH", 1, 0.001, 4, 2)])
    def test_PrimeInvestFixedAddFixedInfo(self, name, currency, LimitMax, LimitMin, returnTime_days,
                                          investEndTime_days):
        "服务商创建项目"
        reps = Prime_InvestFixed_Add_FixedInfo(name, currency, LimitMax, LimitMin, returnTime_days,
                                               investEndTime_days).send()
        assert reps.json()['message'] == "success"
        "服务商查询项目列表"
        reps_PrimeInvestFixedGetFixedInfoList = PrimeInvestFixedGetFixedInfoList().send()
        for i in reps_PrimeInvestFixedGetFixedInfoList.json()['result']['data']:
            "服务商提交审核"
            if i['name'] == Prime_InvestFixed_Add_FixedInfo.testname:
                print(f"""创建项目id是：{i["id"]},提交审核！""")
                resp_AuditSubmit = AuditSubmit(i["id"]).send()
                assert resp_AuditSubmit.json()['message'] == "success"
        rsp_AuditInvestList = AuditInvestListApi().send()

        for i in rsp_AuditInvestList.json()['result']['data']:
            if i['investName'] == Prime_InvestFixed_Add_FixedInfo.testname:
                "运营审核项目"
                resp_AuditInvestStatus = AuditInvestStatus(i['auditId']).send()
                assert resp_AuditInvestStatus.json()['message'] == "success"
                "创建理财策略"
                resp_StrategyAdd = StrategyAdd("固收-" + name + currency + rdm_phone_number(), currency,
                                               i['investId']).send()
                assert resp_StrategyAdd.status_code == 200
